package com.rn.gypsophila.redis.queue.blocking;

import com.rn.gypsophila.redis.basic.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Description：Redis消息消费者
 *
 * @author rannuo
 * @date 2020/5/12
 */
@Slf4j
@Component
public class RedisMessageConsumer implements Runnable {

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public void run() {
        while (true) {
            // 阻塞式brpop，List中无数据时阻塞，参数0表示一直阻塞下去，直到List出现数据
            String message = redisUtils.rightPop("test_msg", 0, TimeUnit.SECONDS);
            log.info("Redis消息消费者接受数据：{}", message);
        }
    }

}
